<?php

class Password
{
	/**
	*@var string
	**/
	private $encryptedPassword;

	/**
	*@var int const
	**/
	const Min_Password_Length = 6;
	/**
	*@var int const
	**/
	const Max_Password_Length = 16;
	/**
	*@var int const
	**/
	const Max_EncryptedPassword_Length = 40;

	/**
	*@param string
	**/
	private function __construct($password)
	{
		if(strlen($password) >= self::Min_Password_Length && 
		   strlen($password) <= self::Max_EncryptedPassword_Length)
		{
			$this->encryptedPassword = $password;
		}
		else
		{
			throw new Exception("Ett fel uppstod i skapande av lösenord");
		}
	}


	/**
	*@param string
	*@return Password
	**/
	public static function createWithEncryptedPassword($encryptedPassword)
	{
		return new Password($encryptedPassword);
	}

	/**
	*@param string
	*@return Password
	**/
	public static function createWithClearTextPassword($password)
	{
		return new Password(Password::EncryptPassword($password));
	}

	/**
	*@return string
	**/
	public function getEncryptedPassword()
	{
		return $this->encryptedPassword;
	}

	/**
	*@return string
	**/
	private static function EncryptPassword($password)
	{
		return sha1($password);
	}
}